<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改合同')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-contract-edit" th:object="${contract}">
            <input id="id" name="id" th:field="*{id}"  type="hidden">
			<div class="form-group">	
				<label class="col-sm-3 control-label">名称：</label>
				<div class="col-sm-8">
					<input id="name" name="name" th:field="*{name}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">合同编号：</label>
				<div class="col-sm-8">
					<input id="contractNo" name="contractNo" th:field="*{contractNo}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">客户：</label>
				<div class="col-sm-8">
					<div class="input-group" style="width: 100%">
						<select id="customerId" name="customerId" class="form-control m-b" th:with="type=${@customer.list()}">
							<option value=""></option>
		                    <option th:each="dict : ${type}" th:text="${dict.name}" th:value="${dict.id}" th:field="*{customerId}"></option>
		                </select>
		            </div>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">商机：</label>
				<div class="col-sm-8">
					<div class="input-group" style="width: 100%">
			            <select id="opportunityId" name="opportunityId" class="form-control m-b" th:with="type=${@opportunity.findByCustomer(contract.customerId)}">
							<option value=""></option>
		                    <option th:each="dict : ${type}" th:text="${dict.name}" th:value="${dict.id}" th:field="*{opportunityId}"></option>
		                </select>
		            </div>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">我方签约人：</label>
				<div class="col-sm-8">
					<div class="input-group" style="width: 100%">
						<select id="ourUserId" name="ourUserId" class="form-control m-b" th:with="type=${@user.list()}">
							<option value=""></option>
		                    <option th:each="dict : ${type}" th:text="${dict.userName}" th:value="${dict.userId}" th:field="*{ourUserId}"></option>
		                </select>
		                <input id="ourUserName" name="ourUserName" class="form-control" type="hidden" th:field="*{ourUserName}">
		            </div>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">客户签约人：</label>
				<div class="col-sm-8">
					<div class="input-group" style="width: 100%">
		                <select id="customerContactId" name="customerContactId" class="form-control m-b" th:with="type=${@contact.findByCustomer(contract.customerId)}">
							<option value=""></option>
		                    <option th:each="dict : ${type}" th:text="${dict.name}" th:value="${dict.id}" th:field="*{customerContactId}"></option>
		                </select>
		                <input id="customerContactName" name="customerContactName" class="form-control" type="hidden" th:field="*{customerContactName}">
		            </div>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">合同金额：</label>
				<div class="col-sm-8">
					<input id="amount" name="amount" th:field="*{amount}" class="form-control" type="number">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">签约日期：</label>
				<div class="col-sm-8">
					<input id="signDate" name="signDate" th:field="*{signDate}" class="form-control time-input" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">开始日期：</label>
				<div class="col-sm-8">
					<input id="startDate" name="startDate" th:field="*{startDate}" class="form-control time-input" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">结束日期：</label>
				<div class="col-sm-8">
					<input id="endDate" name="endDate" th:field="*{endDate}" class="form-control time-input" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">合同说明：</label>
				<div class="col-sm-8">
					<textarea name="remark" autocomplete="off" maxlength="500" class="form-control" rows="3">[[*{remark}]]</textarea>
				</div>
			</div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <div th:include="include::crm-contract-js"></div>
    <script type="text/javascript">
		var prefix = ctx + "crm/contract";
		$("#form-contract-edit").validate({
			rules:{
				name:{
					required:true,
				},
				contractNo:{
					required:true,
				},
			},
			focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/edit", $('#form-contract-edit').serialize());
	        }
	    }
	</script>
</body>
</html>
